package com.btkjgc.utils.junit;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import com.btkjgc.utils.HibernateUtil;
 
@RunWith(JUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:/applicationContext.xml"})
public class TestHibernate {
	
	private static final Logger logger = Logger.getLogger(TestHibernate.class);
	
	@Autowired
	private   SessionFactory sessionFactory;
 
 
	public void setSessionFactory(SessionFactory sessionFactory)
	{
		System.out.println("setSessionFactory");
		this.sessionFactory=sessionFactory;
	}
	
	@Test
	public void test1() {
		
		HibernateUtil.setSessionFactory(sessionFactory);
	 
//		List<AdminUserModel> adminUserList = HibernateUtil.executeSQLQuery("SELECT\n" +
//				"	aut.*,pct.`name` companyname\n" +
//				"FROM\n" +
//				"	admin_user_t aut\n" +
//				"LEFT JOIN property_company_t pct ON aut.companyid = pct.id \n" +
//				"AND pct.del = 0\n" +
//				"WHERE\n" +
//				"	aut.del = 0 and aut.companytype=1",AdminUserModel.class);
//  
//		
//		
//		for (AdminUserModel adminUserModel : adminUserList) {
//			//logger.info(adminUser.getUsername());
//			System.out.println(adminUserModel.getUsername());
//		}
		
		 
//			String	 hql="select d.name as value,d.key from dictionary_t d where name ='Level'";
//	        List<Dictionary> list =  (List<Dictionary>) HibernateUtil.executeSQLQueryList(hql,Dictionary.class);
//	        for (Dictionary dictionary : list) {
//	        	System.out.println(dictionary.getKey());
//			}
			
		
		String hql="select count(*) as a from admin_user_t where loginname ='asad' ";
	 
		int count=HibernateUtil.executeSQLQueryInt(hql);
	}
 
 
}
